package org.feng.controller;

import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import reactor.core.publisher.Flux;

import java.time.LocalDateTime;

/**
 * 代码生成控制器
 *
 * @author mcp
 * @version 1.0
 * @since 2025-05-07 10:21
 */
@Controller
@Slf4j
@RequestMapping("/api/chat")
public class GenerateCodeController {


    @Resource
    private ChatClient chatClient;


    @GetMapping(value = "/test", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @SneakyThrows
    public Flux<String> generateCode( @RequestParam("message") String message) {
        log.info("GenerateCodeController.generateCode(),message:{}", message);

        return chatClient.prompt()
                .system("""
                        当前的时间是%s
                        """.formatted(LocalDateTime.now()))
                .user(message)
                .stream()
                .content();
    }
}


